<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * User测试类
 */

namespace app\test\controller;

use app\utils\BoyeService;
use app\test\controller\Ava;

class User extends Ava {

	//关注用户
  public function focus(){
    if(IS_AJAX){
      $data = [
        'uid'       => I('post.uid',''),
        'focus_uid' => I('post.focus_uid',''),
        'value'     => I('post.value',''),
        'api_ver'   => $this->api_ver,
        'notify_id' => $this->notify_id,
        'alg'       => $this->alg,
        'type'      => 'BY_User_focus',
      ];

      $service = new BoyeService();
      $result  = $service->callRemote("",$data,true);
      echo $this->parseResult($result);
    }else{
      $this->assign('type','BY_User_focus');
      $this->assign('field',[
        ['api_ver','100',LL('need-mark api version')],
        ['uid',42,LL('need-mark user ID')],
        ['focus_uid',50,LL('need-mark focus user ID')],
        ['value',1,LL('need-mark focus (1:yes[default],0:no)')],
      ]);
      echo $this->display('ava/test');
    }
  }

  //天降横财
  public function testMoney(){
    if(IS_AJAX){
      $data = [
				'uid'   => I('post.uid',''),
				'money' => I('post.money',''),
        'api_ver'   => $this->api_ver,
        'notify_id' => $this->notify_id,
        'alg'       => $this->alg,
        'type'      => 'BY_User_testMoney',
      ];

      $service = new BoyeService();
      $result = $service->callRemote("",$data,true);
      echo $this->parseResult($result);
    }else{
      $this->assign('type','BY_User_testMoney');
      $this->assign('field',[
        ['api_ver','100',LL('need-mark api version')],
        ['uid',143,LL('need-mark user ID')],
        ['money',50,LL('need-mark focus user ID')],
      ]);
      echo $this->display('ava/test');
    }
  }

	//手机验证码登陆
	public function loginByCode(){
		if(IS_AJAX){
        $data = array(
						'mobile'    => I('post.mobile',0),
						'code'      => I('post.code',0),
						'api_ver'   =>$this->api_ver,
						'notify_id' =>$this->notify_id,
						'alg'       =>$this->alg,
						'type'      =>'BY_User_loginByCode',
        );

        $service = new BoyeService();
        $result = $service->callRemote("",$data,true);
        echo $this->parseResult($result);
    }else{
    	$this->assign('type','BY_User_loginByCode');
    	$this->assign('code_type',5);//验证码类型
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['mobile','17195862186',LL('need-mark mobile')],
				['code','',LL('need-mark validate-code')],
			]);
	    echo $this->display('register');
    }
	}
	//手机换绑
	public function changePhone(){
    if(IS_AJAX){
        $data = array(
						'uid'       => I('post.uid',0),
						'mobile'    => I('post.mobile',0),
						'code'      => I('post.code',0),
						'password'  => I('post.password',0),
						'api_ver'   =>$this->api_ver,
						'notify_id' =>$this->notify_id,
						'alg'       =>$this->alg,
						'type'      =>'BY_User_changePhone',
        );

        $service = new BoyeService();
        $result = $service->callRemote("",$data,true);
        echo $this->parseResult($result);
    }else{
    	$this->assign('type','BY_User_changePhone');
    	$this->assign('code_type',4);//验证码类型
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid','',LL('need-mark user ID')],
				['mobile','17195862186',LL('need-mark mobile')],
				['code','',LL('need-mark validate-code')],
				['password','111111',LL('need-mark password')],
			]);
	    echo $this->display('register');
    }
  }
	//绑定提现账号 - 仅本站保存下
  public function bindWithdraw(){
    if(IS_AJAX){
        $data = [
					'uid'          => I('post.uid',''),
					'mobile'       => I('post.mobile',''),
					'realname'     => I('post.realname',''),
					'account_type' => I('post.account_type',''),
					'code'         => I('post.code',''),
					'account'      => I('post.account',''),
					'api_ver'   =>$this->api_ver,
					'notify_id' =>$this->notify_id,
					'alg'       =>$this->alg,
					'type'      =>'BY_User_bindWithdraw',
        ];

        $service = new BoyeService();
        $result = $service->callRemote("",$data,true);
        echo $this->parseResult($result);
    }else{
    	$this->assign('type','BY_User_bindWithdraw');
    	$this->assign('code_type',6);//验证码类型
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['account',17195862185,LL('need-mark accout')],
				['realname','',LL('need-mark realname')],
				['code','',LL('need-mark validate-code')],
				['mobile',17195862186,LL('need-mark phone-number')],
				['uid',50,LL('need-mark user ID')],
				['account_type',1,LL('need-mark accout-type')],
			]);
    	echo $this->display('register');
    }
  }
	//手机绑定并设置密码 - 微信登陆用
  public function bind(){
    if(IS_AJAX){
        $data = [
					'uid'       => I('post.uid',0),
					'mobile'    => I('post.mobile',0),
					'code'      => I('post.code',0),
					'password'  => I('post.password',0),
					'api_ver'   =>$this->api_ver,
					'notify_id' =>$this->notify_id,
					'alg'       =>$this->alg,
					'type'      =>'BY_User_bind',
        ];

        $service = new BoyeService();
        $result = $service->callRemote("",$data,true);
        echo $this->parseResult($result);
    }else{
    	$this->assign('type','BY_User_bind');
    	$this->assign('code_type',3);//验证码类型
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['mobile','17195862186',LL('need-mark phone-number')],
				['uid','42',LL('need-mark user ID')],
				['password','123456',LL('need-mark password')],
				['code','',LL('need-mark validate-code')],
			]);
    	echo $this->display('register');
    }
  }
	//手机找回密码
  public function findPswByMobile(){
      if(IS_AJAX){
          $data = [
          		'uid'       => I('post.uid',0),
							'mobile'    => I('post.mobile',''),
							'code'      => I('post.code',''),
							'psw'       => I('post.psw',''),
							'api_ver'   =>$this->api_ver,
							'notify_id' =>$this->notify_id,
							'alg'       =>$this->alg,
							'type'      =>'BY_User_findPswByMobile',
          ];

          $service = new BoyeService();
          $result= $service->callRemote("",$data,true);
          echo $this->parseResult($result);
      }else{
      	$this->assign('type','BY_User_findPswByMobile');
      	$this->assign('code_type',2);//验证码类型
				$this->assign('field',[
					['api_ver',$this->api_ver,LL('need-mark api version')],
					['uid','',LL('need-mark user ID')],
					['mobile','17195862186',LL('need-mark mobile')],
					['code','',LL('need-mark validate-code')],
					['psw','111111',LL('need-mark new password')],
				]);
	      echo $this->display('register');
      }
  }
  //根据现密码修改密码
  public function updatePsw(){
        if(IS_AJAX){
          $data = [
          		'uid'       => I('post.uid',0),
							'old_psw'   => I('post.old_psw',0),
							'psw'       => I('post.psw',0),
							'api_ver'   =>$this->api_ver,
							'notify_id' =>$this->notify_id,
							'alg'       =>$this->alg,
							'type'      =>'BY_User_updatePsw',
          ];

          $service = new BoyeService();
          $result = $service->callRemote("",$data,true);
          echo $this->parseResult($result);
        }else{
					$this->assign('type','BY_User_updatePsw');
					$this->assign('field',[
						['api_ver',$this->api_ver,LL('need-mark api version')],
						['uid','',LL('need-mark user ID')],
						['old_psw','123456',LL('need-mark old password')],
						['psw','123456',LL('need-mark new password')],
					]);
	        echo $this->display('ava/test');
        }
  }
	//测试用户注册
  public function register(){
    if(IS_AJAX){
      $data = array(
					'username'    => I('post.username',''),
					'password'    => I('post.password',''),
					'code'        => I('post.code',''),
					'reg_type'    => I('post.reg_type',3,'int'),
					'sex'         => I('post.sex',0,'int'),
					'from'        => I('post.from',0,'int'),
					'email'       => I('post.email','','email'),
					'invite_code' => I('post.invite_code',''),
					'api_ver'     => $this->api_ver,
					'notify_id'   => $this->notify_id,
					'alg'         => $this->alg,
					'type'        => 'BY_User_register',
      );
      $service = new BoyeService();
      $result = $service->callRemote("",$data,true);
      echo $this->parseResult($result);

    }else{
    	$this->assign('type','BY_User_register');
    	$this->assign('code_type',1);//验证码类型
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['username','rainbow',LL('need-mark username reg username')],
				['password','123456',LL('need-mark password')],
				['code','',LL('need-mark mobile validate-code reg-code')],
				['reg_type',3,LL('need-mark reg-type')],
				['from',0,LL('need-mark reg-from')],
				['sex','',L('reg-sex')],
				['email','',L('email')],
				['invite_code','',L('invite-code')],
			]);
      echo $this->display();
    }

  }

  //测试用户资料更新
  public function update(){
  	if(IS_AJAX){
  		$data = array(
				'uid'       => I('post.uid',0),
				'mobile'    => I('post.mobile',''),
				'realname'  => I('post.realname',''),
				'email'     => I('post.email',''),
				'birthday'  => I('post.birthday',0),
				'nickname'  => I('post.nickname',''),
				'sex'       => I('post.sex',''),
				'qq'        => I('post.qq',''),
				// 'alipay'    => I('post.alipay',''),
				// 'head'      => I('post.head',''),
				'idnumber'  => I('post.idnumber',''),
				'sign'  		=> I('post.sign',''),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_User_update',
      );

  		$service = new BoyeService();
      $result = $service->callRemote("",$data,true);
      echo $this->parseResult($result);
  	}else{
  		$this->assign('type','BY_User_update');
			$this->assign('field',[
				['api_ver','100',LL('need-mark api version')],
				['uid','0',LL('need-mark user ID')],
				['mobile','',L('mobile')],
				['realname','',L('realname')],
				['email','',L('email')],
				['birthday','',L('birthday')],
				['nickname','',L('nickname')],
				['sex','',L('reg-sex')],
				['qq','',L('qq')],
				// ['alipay','',L('alipay-account')],
				// ['head','',L('head')],
				['idnumber','',L('idnumber')],
				['sign','',LL('user sign')],
			]);
  		echo $this->display('ava/test');
  	}
  }

	//测试用户登陆
	public function login(){
		if(IS_AJAX){
      $data = array(
        'username' => I('post.username',''),
        "password" => I('post.password',''),
        'api_ver'  =>$this->api_ver,
        'notify_id'=>$this->notify_id,
        'alg'			 =>$this->alg,
        'type'		 =>'BY_User_login',
      );

      $service = new BoyeService();
      $result = $service->callRemote("",$data,true);
      echo $this->parseResult($result);
    }else{
    	$this->assign('type','BY_User_login');
			$this->assign('field',[
				['api_ver','100',LL('need-mark api version')],
				['username','rainbow',LL('need-mark username or phone-number')],
				['password','123456',LL('need-mark password')],
			]);
    	echo $this->display('ava/test');
    }
	}

    //测试用户code登陆
    public function loginBySession(){
        if(IS_AJAX){
            $data = array(
                'uid' => I('post.uid',''),
                "login_session" => I('post.login_session',''),
                'api_ver'  =>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'alg'			 =>$this->alg,
                'type'		 =>'BY_User_loginBySession',
            );

            $service = new BoyeService();
            $result = $service->callRemote("",$data,true);
            echo $this->parseResult($result);
        }else{
            $this->assign('type','BY_User_login');
            $this->assign('field',[
                ['api_ver','100',LL('need-mark api version')],
                ['uid','17',LL('need-mark uid')],
                ['login_session','123456',LL('need-mark session')],
            ]);
            echo $this->display('ava/test');
        }
    }


  public function getCode(){
		$mobile = I('mobile','');
		$type   = I('type','');

		$data = array(
				'mobile'    =>$mobile,
				'code_type' =>$type,
				'alg'       =>$this->alg,
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'type'      =>'BY_Message_send_sms',
		);

		$service = new BoyeService();
		$result= $service->callRemote("",$data,true);
		echo $this->parseResult($result);
  }

	public function __construct(){
		parent::__construct();
	}
}